package com.medistat.controllers;


import java.io.Serializable;
import java.util.Calendar;
import java.util.List;

import javax.faces.bean.SessionScoped;

import org.springframework.stereotype.Controller;

import com.medistat.dialog.Schedule;
import com.medistat.helpers.UrlConsts;
import com.medistat.util.DateUtils;


@Controller("loadScheduleController")
@SessionScoped
public class LoadScheduleController extends ScheduleController implements Serializable{

	private static final long serialVersionUID = 1013471170087129339L;
	
	@Override
	public String getPageName() {
		return UrlConsts.LOAD_SCHEDULE_PAGE;
	}

	
	//events
	public void loadSchedule() {
		List<Schedule> schedules = null;
		try {
			Calendar dateFrom = DateUtils.convertDateToCalendar(getDateFrom());
			schedules = getDialogService().loadSchedule(dateFrom);
			showFreeDays();
		} catch(AssertionError e) {
			addError(e.getMessage());
		} catch (Exception e) {
			addWarning(e.getMessage());
		}
		setSchedules(schedules);
	}	
}
